/**
 * <b>项目名：</b>ht-web<br/>  
 * <b>包名：</b>com.flea.hclv.controller<br/>  
 * <b>文件名：</b>PersonInfoController.java<br/>  
 * <b>版本信息：</b>1.0<br/>  
 * <b>日期：</b>2019年8月8日 上午11:25:34<br/>  
 * <b>COPYRIGHT 2010-2012 ALL RIGHTS RESERVED 虫子科技</b>-版权所有<br/>
 */
package com.flea.hclv.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.entity.HVisitor;
import com.flea.hclv.model.entity.PersonInfo;
import com.flea.hclv.service.PersonInfoService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.platform.session.FleaOrgUtils;

/**
 * @description TODO
 * @createTime 2019年8月8日 上午11:25:34
 * @modifyTime 
 * @author myflea@163.com
 * @version 1.0
 */
@Controller
@RequestMapping("/flea/hclv/person/")
public class PersonInfoController {
	@Autowired
	private PersonInfoService personInfoService;
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public ServerResponse<String> saveOrUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String userId = FleaOrgUtils.getCurUserUuid(request);
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        String model = request.getParameter("model");

        PersonInfo personInfo = JSON.parseObject(model,PersonInfo.class);
        ServerResponse<String> serverResponse = personInfoService.saveOrUpdate(userId,currentUserDept,personInfo);
        return serverResponse;
    }
    /**
     * 查找所有  （供管理员使用）
     * @param request request
     * @param paging 分页对象
     * @param zhName 中文名字
     * @param enName 英文名
     * @return list
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public ServerResponse<FleaPage<PersonInfo>> selectAll(HttpServletRequest request, FleaPage<HVisitor> paging,
                                                        @RequestParam(value = "projectCode",defaultValue = "")String projectCode,
                                                        @RequestParam(value = "personNo",defaultValue = "")String personNo,
                                                        @RequestParam(value = "name",defaultValue = "")String name,
                                                        @RequestParam(value = "sex",defaultValue = "")String sex,
                                                        @RequestParam(value = "startTime",defaultValue = "")String startTime,
                                                        @RequestParam(value = "endTime",defaultValue = "")String endTime
                                                        ){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        return personInfoService.selectAll(paging.getCurPage(),paging.getPageSize(),projectCode,name,personNo,sex,startTime,endTime);

    }
    @RequestMapping("deleteByIds")
    @ResponseBody
    public ServerResponse<String> deleteByIds(HttpServletRequest request,HttpServletResponse response, @RequestParam("ids")String ids){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        List<String> idList = JSON.parseArray(ids,String.class);
        ServerResponse<String> serverResponse =  personInfoService.deleteByIds(userId,idList);
        return serverResponse;
    }

}
